package com.bugstack.domain.credit.event;

import com.bugstack.types.event.BaseEvent;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @Author: czb
 * @Description: TODO
 * @DateTime: 2025/4/17 14:47
 **/
@Component
public class CreditAdjustSuccessEvent extends BaseEvent<CreditAdjustSuccessEvent.CreditAdjustSuccessMessage> {

    @Value("${spring.rabbitmq.topic.send_credit_adjust}")
    private String topic;

    @Override
    public EventMessage<CreditAdjustSuccessMessage> buildEventMessage(CreditAdjustSuccessMessage data) {
        return EventMessage.<CreditAdjustSuccessMessage>builder()
                .id(RandomStringUtils.randomAlphanumeric(11))
                .timestamp(new Date())
                .data(data)
                .build();
    }

    @Override
    public String topic() {
        return topic;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    public static class CreditAdjustSuccessMessage{
        //用户id
        private String userId;
        //订单id
        private String orderId;
        //调整金额
        private BigDecimal amount;
        //外部透传业务防重码
        private String outBusinessNo;

    }

}
